﻿using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Windows.Media.Imaging;
using VisualWip.PresentationModel;

namespace VisualWip.SingleJpegFileRecorder
{
    [Export(typeof (IBoardRecorder))]
    public class SingleLocalJpegFileBoardRecorder : IBoardRecorder
    {
        #region IBoardRecorder Members

        public void SaveRecording(BitmapSource screenRecording)
        {
            var dir = new DirectoryInfo(@"Captures\");

            if (!dir.Exists)
            {
                dir.Create();
            }

            var encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(screenRecording));
            string fileName = string.Format(@"{0} {1:s}{2}", RecordingName, DateTime.Now, ".jpeg").Replace(":", "");

            string filePath = Path.Combine(dir.FullName, fileName);

            using (Stream stm = File.Create(filePath))
            {
                encoder.Save(stm);
            }
        }

        public bool CanRecord
        {
            get { return true; }
        }

        public string RecordingName { get; set; }

        #endregion
    }
}